package com.zhuss.order.processor;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.order.order.SearchOrderRefundBo;
import com.zhuss.bean.vo.order.order.ListOrderRefundVo;
import com.zhuss.common.PageVo;
import com.zhuss.exception.DzcxException;
import com.zhuss.exception.ExceptionCode;
import com.zhuss.order.db.dao.ext.OrderRefundDao;
import com.zhuss.order.db.entity.OrderRefund;


/**
 * @description: 退款订单读
 * @author: zhushanshuo
 * @create: Fri Jan 15 21:22:09 CST 2021
 **/
@Component("orderRefundRead")
public class OrderRefundRead {
	
	@Autowired
	private OrderRefundDao orderRefundDao;
	
	
	
	/**
	 * 退款订单
	 * @return
	 */
	public Object listOrderRefund(List<Long> orderRefundIdList) {
		List<OrderRefund> result = orderRefundDao.listById(orderRefundIdList);
		return result;
	}
	
	
	/**
	 * 根据名字查询退款订单
	 * @param 
	 * @return
	 */
	public List<OrderRefund> list(String name) {
		List<OrderRefund> result = orderRefundDao.listByName(name);
		return result;
	}
	
	public List<OrderRefund> listNotId(String name, Long orderRefundId) {
		List<OrderRefund> result = new ArrayList<OrderRefund>();
		List<OrderRefund> list = list(name);
		for (OrderRefund c : list) {
			if (!c.getOrderRefundId().equals(orderRefundId)) {
				result.add(c);
				break;
			}
		}
		return result;
	}
	
	/**
	 * 退款订单 
	 * @return
	 */
	public Object listOrderRefundId() {
		List<OrderRefund> orderRefundList = orderRefundDao.listAll();
		List<Long> result = new ArrayList<>();
		transferListId(orderRefundList, result);
		return result;
	}
	
	private void transferListId(List<OrderRefund> orderRefundList, List<Long> result) {
		for (OrderRefund item : orderRefundList) {
			result.add(item.getOrderRefundId());
		}
	}

	/**
	 * 退款订单列表
	 * @param bo
	 * @return
	 */
	public Object list(SearchOrderRefundBo bo) {
		PageVo<ListOrderRefundVo> result = new PageVo<ListOrderRefundVo>();
        result.setPageNum(bo.getPageNum());
        result.setPageSize(bo.getPageSize());
        result.setItems(orderRefundDao.list(bo));
        result.setTotal(orderRefundDao.countList(bo));
		return result;
	}
	
	/**
	 * 退款订单详情
	 * @param orderRefundId
	 * @return
	 * @throws DzcxException
	 */
	public Object detail(Long orderRefundId) throws DzcxException {
		Object result = orderRefundDao.detail(orderRefundId);
		if (result == null) {
			throw new DzcxException(ExceptionCode.数据不存在);
		}
		return result;
	}
	
	

}
